IF EXISTS(SELECT 1 FROM master..sysdatabases WHERE [name] = 'dom_CDB')
BEGIN

	DECLARE Connections CURSOR
	READ_ONLY
	FOR
		SELECT spid FROM master..sysprocesses WHERE dbid=db_id('dom_CDB')
		
	DECLARE @SPID INT
	DECLARE @SQL NVARCHAR(50)
	
	OPEN Connections
	FETCH NEXT FROM Connections INTO @SPID
	
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN
			SET @SQL = 'KILL ' + CAST(@SPID AS VARCHAR(10))
			EXEC SP_EXECUTESQL @SQL
		END
		FETCH NEXT FROM Connections INTO @SPID
	END
	
	CLOSE Connections
	DEALLOCATE Connections
	
	DROP DATABASE dom_CDB
END

IF NOT EXISTS(SELECT 1 FROM master..sysdatabases WHERE [name] = 'dom_CDB')
BEGIN
	CREATE DATABASE dom_CDB
	ALTER DATABASE dom_CDB SET RECOVERY FULL
END
GO